﻿using System.Collections.Generic;

namespace SmartSpace
{
    public class ServiceResult
    {
        public bool IsSuccess { get; set; }
        public string Message { get; set; }

        /// <summary>
        /// true,success
        /// </summary>
        public ServiceResult()
            : this(true, "success")
        {
        }

        public ServiceResult(bool isSuccess)
        {
            this.IsSuccess = isSuccess;
            if (this.IsSuccess)
            {
                this.Message = "success";
            }
            else
            {
                this.Message = "failure";
            }
        }

        public ServiceResult(bool isSuccess, string message)
        {
            IsSuccess = isSuccess;
            Message = message;
        }
    }

    public class SingleResult<T> : ServiceResult
    {
        public T Data { get; private set; }
        public SingleResult()
            : this(false, "获取失败!", default(T))
        {
        }

        public SingleResult(T data)
            : base(true, "获取成功!")
        {
            Data = data;
        }

        public SingleResult(bool isSuccess, string message, T data)
            : base(isSuccess, message)
        {
            Data = data;
        }
    }

    public class ListResult<T> : ServiceResult
    {
        public List<T> Data { get; private set; }

        public ListResult()
            : this(false, "获取失败!", null)
        {
        }

        public ListResult(List<T> data)
            : base()
        {
            Data = data;
        }

        public ListResult(bool isSuccess, string message, List<T> data)
            : base(isSuccess, message)
        {
            Data = data;
        }
    }

    public class PagedResult<T> : ServiceResult
    {
        public int Start { get; private set; }
        public int Limit { get; private set; }
        public int Total { get; private set; }
        public List<T> Data { get; private set; }

        public PagedResult()
            : this(false, "获取失败!", 0, 0, 0, null)
        {
        }

        public PagedResult(int start, int limit, int total, List<T> data)
            : base()
        {
            Start = start;
            Limit = limit;
            Total = total;
            Data = data;
        }

        public PagedResult(bool isSuccess, string message, int start, int limit, int total, List<T> data)
            : base(isSuccess, message)
        {
            Start = start;
            Limit = limit;
            Total = total;
            Data = data;
        }
    }
}